package com.xone.collaboration.service.impl.process;

import com.alibaba.fastjson.JSON;
import com.xone.collaboration.service.OperationProcess;
import com.xone.collaboration.service.PushService;
import com.xone.collaboration.service.vo.OperationResult;
import com.xone.push.center.client.PushMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Order(3)
public class PushMessageProcess implements OperationProcess {

    @Autowired
    private PushService pushService;

    @Value("${push.appId}")
    private String appId;

    @Value("${push.topic}")
    private String topic;

    @Override
    public OperationResult process(OperationContext context) {

        PushMessage message = new PushMessage();
        message.setAppId(appId);
        message.setTopic(topic);
        message.setMessage(JSON.toJSONString(context));
        pushService.sendMessage(message);
        return OperationResult.of(true,null);
    }

    @Override
    public boolean needRun(OperationContext context) {
        return context.getNeedRun();
    }
}
